package com.zoro.jianyue.presenter.impl;

import android.content.Context;

import com.zoro.jianyue.R;
import com.zoro.jianyue.bean.ImagesListEntity;
import com.zoro.jianyue.bean.ResponseImagesListEntity;
import com.zoro.jianyue.common.Constants;
import com.zoro.jianyue.interactor.CommonListInteractor;
import com.zoro.jianyue.interactor.impl.ImagesListInteractorImpl;
import com.zoro.jianyue.lisneter.BaseMultLoadedlistener;
import com.zoro.jianyue.presenter.ImagesListPresenter;
import com.zoro.jianyue.view.ImagesListView;

/**
 * Created by CM-ZR on 2016/1/29.
 */
public class ImagesListPresenterImpl implements ImagesListPresenter, BaseMultLoadedlistener<ResponseImagesListEntity> {

    private Context mContext;
    private ImagesListView mImagesListView;
    private CommonListInteractor mCommonListInteractor;

    public ImagesListPresenterImpl(Context context, ImagesListView imagesListView) {
        this.mContext = context;
        this.mImagesListView = imagesListView;
        mCommonListInteractor = new ImagesListInteractorImpl(this);
    }

    @Override
    public void loadListData(String requestTag, int event_tag, String keywords, int page, boolean isSwipeRefresh) {
        mImagesListView.hideLoading();
        if (!isSwipeRefresh) {
            mImagesListView.showLoading(mContext.getString(R.string.common_loading_message));
        }
        mCommonListInteractor.getCommonListData(requestTag, event_tag, keywords, page);
    }

    @Override
    public void onItemClickListener(int position, ImagesListEntity entity, int x, int y, int width, int height) {
        mImagesListView.navigateToImagesDetail(position, entity, x, y, width, height);
    }

    @Override
    public void onSuccess(int event_tag, ResponseImagesListEntity data) {
        mImagesListView.hideLoading();
        if (event_tag == Constants.EVENT_REFRESH_DATA) {
            mImagesListView.refreshListData(data);
        } else if (event_tag == Constants.EVENT_LOAD_MORE_DATA) {
            mImagesListView.addMoreListData(data);
        }
    }

    @Override
    public void onError(String msg) {
        mImagesListView.hideLoading();
        mImagesListView.showError(msg);
    }

    @Override
    public void onException(String msg) {
        mImagesListView.hideLoading();
        mImagesListView.showError(msg);
    }
}
